"use client"; import { ServiceTypes } from "@/api/customservice"; import { getPaysApi, lredPacketApi, PayDataType, redPacketApi } from "@/api/promo"; import RedPacketModal, { RedPacketModalProps } from "@/components/Box/RedPacketModal"; import SlotsModal, { SlotModalRefProps } from "@/components/Box/SlotsModal"; import UserRecharge, { ModalRefProps, Timeout } from "@/components/Box/UserRecharge"; import WheelModal, { WheelModalProps } from "@/components/Box/WheelModal"; import { getWheelApi } from "@/api/cashWheel"; import { getGiveInfoApi } from "@/api/slots"; import { Link } from "@/i18n/routing"; import { useGlobalNoticeStore } from "@/stores/useGlobalNoticeStore"; import { useSocialStore } from "@/stores/useSocials"; import useWheelStore from "@/stores/useWheelStore"; import { getToken } from "@/utils/Cookies"; import { useRequest } from "ahooks"; import { Badge } from "antd-mobile"; import { useTranslations } from "next-intl"; import Image from "next/image"; import { FC, useEffect, useRef } from "react"; interface Props { services: ServiceTypes[]; socials: ServiceTypes[]; } const ServiceWidget: FC = (props) => { const token = getToken(); const { services, socials = [] } = props; const { wheelStatus, wheelCurrent, setWheel } = useWheelStore((state) => ({ wheelStatus: state.status, wheelCurrent: state.currentWheel, setWheel: state.setWheel, })); const defaultService = services?.find((item) => item.is_suspend === 1); const newServices = services?.filter((item) => item.status === 1) || []; const setSocials = useSocialStore((state) => state.setSocials); const redPacketModalRef = useRef(null); /// 首充活动ref const userRechargeRef = useRef(null); // 轮盘 const wheelModalRef = useRef(null); const slotsRef = useRef(null); const getWheel = () => { if (!getToken()) return Promise.resolve(undefined); return getWheelApi().then((res) => { return res.data; }); }; useEffect(() => { // 数据存储,侧边栏使用 setSocials(socials); setWheel().then((data) => { if (data && useWheelStore.getState().status === 1) { wheelModalRef.current?.onOpen(data); } }); }, []); const t = useTranslations("HomePage"); const { unread, userUnred } = useGlobalNoticeStore((state) => ({ unread: state.unread, userUnred: state.userUnred, })); const getRedPacketInfo = async () => { try { let redPacketInfo: any; let actList: any = []; if (token) { redPacketInfo = await lredPacketApi(); actList = redPacketInfo.data?.red_packets || []; } else { redPacketInfo = await redPacketApi(); actList = redPacketInfo.data || []; } // 是否有已开始但是没领过的红包 return actList.filter((aItem: any) => { return aItem.can_receive && aItem.is_start && !aItem.is_receive; }); } catch (error) { console.log("redPacketInfo===>error:", error); } }; // 红包雨轮询 const { data: packets, run } = useRequest(getRedPacketInfo, { pollingInterval: 5000, pollingErrorRetryCount: 1, pollingWhenHidden: false, }); // 首充活动 const getPayInfo = async (): Promise => { if (token) { const result = await getPaysApi(); return result.data; } else { return Promise.resolve({ first_pay: [], pay: [], }); } }; const { data: paysInfo, run: payRun } = useRequest(getPayInfo, { pollingErrorRetryCount: 1, pollingWhenHidden: false, }); /** * 免费送活动 */ const getSlots = async () => { if (token) { const result = await getGiveInfoApi(); return result.data; } else { return Promise.resolve({}); } }; const { data: slots, run: slotRun } = useRequest(getSlots, { pollingErrorRetryCount: 1, pollingWhenHidden: false, }); const slotHandler = () => { slotsRef.current?.onOpen(slots); }; return ( <>
{slots?.id ? ( ) : null} {/*轮盘 */} {wheelStatus === 2 ? ( {"wheel"} ) : null} {/*首充*/} {paysInfo?.first_pay?.map((item, index) => { return (
{ // @ts-ignore userRechargeRef.current?.onOpen(paysInfo.first_pay, index); }} /> {item.end_time > 0 ? ( ) : null}
); })} {/* 红包雨icon */} {packets?.map((item, index) => { return (
{ redPacketModalRef.current?.onOpen(packets, index); }} />
); })} {/*未读消息*/} {unread || userUnred ? ( ) : null} {defaultService && ( {""} )}
{/*红包雨弹窗*/} {/*首充弹窗*/} {/* 轮盘弹窗 */} {/*随机送*/}
= 5 ? 5 : (newServices?.length ?? 1)},1fr)`, }} > {newServices.map((service, index) => { return ( ); })}
{t("Service")}
{/*share*/}
{t("Share")}
= 5 ? 5 : socials.length},1fr)`, }} > {socials.map((service, index) => { return ( ); })}
); }; export default ServiceWidget;